<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_bufee/model')->方法名();
*/
namespace jy_bufee;
defined('BY_JYA') or exit('error');
class model extends \plugin{
	/*
		更新用户
	*/
	function upmember($member,$downmids=array(),$next_level=array()){
		if(!$member['level_id'] && $downmids){
			$goods_ids=json_decode($next_level['goods_ids'],true);
			$goodskeys=array();
			foreach($goods_ids as $g){
				$goodskeys[]=$g['id'];
			}
			$goodskeys=$goodskeys?:-1;
			$update=array(
				'agent_id'=>$member['agent_id']
			);
			foreach($downmids as $mid){
				$goods_ids=json_decode($lv['goods_ids'],true);
				$isbuynum=pdo_getsum('jy_weishop_order_goods',array('ispay'=>1,'mid'=>$mid,'goodsid'=>$goodskeys),'total');
				if($isbuynum>0){
					pdo_update('jy_commission_member',$update,array('mid'=>$mid));
				}			
			}
			$isbunum=pdo_count('jy_commission_member',array('is_buwei'=>2,'agent_id'=>$member['agent_id']),'mid');
			$basic=$this->plugin_setting('basic');
			if($basic['buwei_num'] && $isbunum>=$basic['buwei_num']){
				return false;
			}
			pdo_update('jy_commission_member',array('is_buwei'=>1),array('mid'=>$member['mid']));
		}
		return true;
	}
	/*
		补位用户
	*/
	function bumember($member,$parent_id=0){
		$isbunum=pdo_count('jy_commission_member',array('is_buwei'=>2,'agent_id'=>$parent_id),'mid');
		$basic=$this->plugin_setting('basic');
		if($basic['buwei_num'] && $isbunum>=$basic['buwei_num']){
			return $parent_id;
		}
		$buwei_mid=pdo_getcolumn('jy_commission_member',array('is_buwei'=>1,'agent_id'=>$parent_id,'uniacid'=>$_SESSION['uniacid']),'mid');
		$parent_id=$buwei_mid?:$parent_id;
		if($buwei_mid){
			pdo_update('jy_commission_member',array('is_buwei'=>2),array('mid'=>$buwei_mid));
		}
		return $parent_id;
	}
}
?>